# $Id$
# Maintainer: Dave Reisner <dreisner@archlinux.org>
# Contributor: Jaroslav Lichtblau <dragonlord@aur.archlinux.org>
# Contributor: Douglas Soares de Andrade
# Contributor: Roberto Alsina <ralsina@kde.org>

pkgname=varnish
pkgver=5.1.3
pkgrel=1
pkgdesc="High-performance HTTP accelerator"
arch=('i686' 'x86_64')
url="https://www.varnish-cache.org/"
license=('BSD')
depends=('gcc' 'libedit' 'pcre')
makedepends=('python-docutils')
optdepends=('python: needed for vmod development')
backup=('etc/varnish/default.vcl')
install=$pkgname.install
source=("https://repo.varnish-cache.org/source/$pkgname-$pkgver.tar.gz"
        varnish-vcl-reload
        varnish.service
        varnish.sysusers)
sha256sums=('7439c93ca581340f3722b8c790160f46dc6c5328188e4c0bc233c42f3f04a54e'
            '0369e3e735e4c6150f08677df8b7cdae1a36ea75fd0e03734abe814a94312f80'
            '069904391237641eb770e8bc3989d18a3b3a9cb2374b9cd525235bfbb49b6b1d'
            'b58dd6b00eb81c75e4bb30421b85b2be88c049d5b72a8ee553ba690a5414972b')

build() {
  cd "$pkgname-$pkgver"

  # https://github.com/varnishcache/varnish-cache/issues/1875
  [[ $CARCH == i686 ]] && CFLAGS+=' -fexcess-precision=standard'

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var/lib \
    --sbindir=/usr/bin

  make
}

check() {
  cd "$pkgname-$pkgver"

  # Sometimes fails on i686 in address remapping test. Not sure if flaky
  # test or otherwise...
  make check
}

package() {
  cd "$pkgname-$pkgver"

  make DESTDIR="$pkgdir" install

  install -m755 "$srcdir/varnish-vcl-reload" "$pkgdir/usr/bin"
  install -Dm644 "$srcdir/$pkgname.service" "$pkgdir/usr/lib/systemd/system/$pkgname.service"

  # create varnish:varnish user/group
  install -Dm644 "$srcdir/$pkgname.sysusers" "$pkgdir/usr/lib/sysusers.d/varnish.conf"

  # config
  install -Dm644 "etc/example.vcl" "$pkgdir/etc/varnish/default.vcl"
  install -Dm644 "etc/builtin.vcl" "$pkgdir/usr/share/doc/varnish/builtin.vcl"

  # license
  install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
